const app = getApp();
var util = require('../../utils/util.js');
var api = require('../../utils/api.js');
var user = require('../../utils/user.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    radioItems: [
      { name: '商家地址不符', value: '1' },
      { name: '商家电话号码为空', value: '2' },
      { name: '商家电话号码不符', value: '3' },
      { name: '商家业务变更', value: '4' }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      phoneId: options.phoneId
    });
  },
  radioChange: function (e) {
    var radioItems = this.data.radioItems
    var errorId = ""
    var checked = e.detail.value
    for (var i = 0; i < radioItems.length; i++) {
      if (checked.indexOf(radioItems[i].name) !== -1) {
        radioItems[i].checked = true
        errorId = radioItems[i].value
      } else {
        radioItems[i].checked = false
      }
    }
    this.setData({
      radioItems: radioItems,
      errorId: errorId
    })
  },
  errorReport: function() {
    var t = this
    wx.showLoading({
      title: '提交中...',
    });
    var data = {}
    data.phoneId = t.data.phoneId
    data.errorId = t.data.errorId
    var errorId = t.data.errorId;
    if (!data.errorId || data.errorId == "") {
      util.showError('请选择错误类型');
      return;
    }
    
    data.token = app.globalData.token
    user.request(api.errorReport, data, function(data){
      wx.hideLoading();
      util.showError('提交成功，感谢您的支持')
      setTimeout(function() {
        wx.navigateBack()
      }, 1000);
    })

    wx.navigateTo({
      url: '',
    })
  }
})